package luit.mmt02.secutity;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class checkmailaddress {
	private Pattern pattern;
    private Matcher matcher;
    private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    public checkmailaddress() {
        pattern = Pattern.compile(EMAIL_PATTERN);
    }

    //hop le la true; ko hop le la false;
    public boolean kiemtrahople(String diachiemail) {
        matcher = pattern.matcher(diachiemail);
        return matcher.matches();
    }

    //neu kiem tra co bat ky mail nao ko hop le thi lap tuc return false;
    public boolean kiemtrahoples(String[] diachiemails){
        boolean flaghople = true;
        for(int i = 0;i<diachiemails.length;i++){
            flaghople = this.kiemtrahople(diachiemails[i]);
            if(!flaghople){
                return flaghople; //return false khi ko hop le;
            }
        }
        return flaghople;//ket qua tat ca dia chi deu hop le;
    }
    
    public boolean check_mailhople(String email)
    {
    	String []arr = email.split("@");
    	if(arr.length >= 2)
    		return true;
    	else return false;
    }
}
